nutanixPortal
    
    //登录验证
    .service('apiService', function ($q, $http, ENV) {

      this.checkConnection = function () {
        return $q(function (resolve, reject) {
          $http.get(ENV.apiUrl + '/settings')
            .success(resolve)
            .error(reject);
        });
      };

    })
    .service('userService', function () {
        this.loginUser = '';
        
    })


    // =========================================================================
    // Header Messages and Notifications list Data
    // =========================================================================
    .service('messageService', ['$resource', function($resource){
        this.getMessage = function(img, user, text) {
            var gmList = $resource("data/messages-notifications.json");
            
            return gmList.get({
                img: img,
                user: user,
                text: text
            });
        }
    }])
    

    // =========================================================================
    // Best Selling Widget Data (Home Page)
    // =========================================================================

    .service('bestsellingService', ['$resource', function($resource){
        this.getBestselling = function(img, name, range) {
            var gbList = $resource("data/best-selling.json");
            
            return gbList.get({
                img: img,
                name: name,
                range: range,
            });
        }
    }])

    // =========================================================================
    // Best Selling Widget Data (Home Page)
    // =========================================================================

    .service('vmService', ['$http', function($http){
        var scope = this;
        this.vms = [];

        $http({
            method: 'GET',
            url: 'http://192.168.1.115:9000/PrismGateway/services/rest/v1/vms/',
          }).then(function successCallback(response){
            scope.vms = response.data.entities;
            console.log(scope, scope.vms);
          });
          
        this.addVM = function(name, host, ip, cpu, memory, disks) {
            var newVM = {
              "name": name,
              "memoryMb": memory,
              "numVcpus": cpu,
              "haPriority": "integer",
              "hostId": "string",
              "hypervisorType": "enums.HypervisorType$Enum",
              "bootConfig": {
                "bootDeviceType": "dto.acropolis.BootConfigDTO$BootDeviceType",
                "diskAddress": {
                  "deviceBus": "dto.acropolis.VMDiskAddressDTO$DeviceBus",
                  "deviceIndex": "integer"
                },
                "macAddr": "string"
              },
              "memoryReservationMb": "integer",
              "containerUuid": "string",
              "numCoresPerVcpu": "integer",
              "description": "string",
              "uuid": "string",
              "vcpuReservationHz": "integer",
              "vmCustomizationConfig": {
                "datasourceType": "dto.acropolis.VMCustomizationConfigDTO$DatasourceType",
                "filesToInjectList": [
                  {
                    "destinationPath": "string",
                    "sourcePath": "string"
                  }
                ],
                "freshInstall": false,
                "userdata": "string",
                "userdataPath": "string"
              },
              "vmDisks": [
                {
                  "diskAddress": "create.dto.acropolis.VMDiskAddressDTO",
                  "isCdrom": false,
                  "isEmpty": false,
                  "isScsiPassThrough": false,
                  "isThinProvisioned": false,
                  "vmDiskClone": {
                    "containerUuid": "string",
                    "imagePath": "string",
                    "minimumSize": "integer",
                    "minimumSizeMb": "integer",
                    "ndfs_filepath": "string",
                    "snapshotGroupId": "string",
                    "vmDiskUuid": "string",
                    "vmdisk_uuid": "string"
                  },
                  "vmDiskCreate": {
                    "containerId": "integer",
                    "containerName": "string",
                    "containerUuid": "string",
                    "size": "integer",
                    "sizeMb": "integer"
                  }
                }
              ],
              "vmNics": [
                {
                  "networkUuid": "string",
                  "macAddress": "string",
                  "model": "string",
                  "requestIp": false,
                  "requestedIpAddress": "string"
                }
              ]
            }

            $http({
                method: 'POST',
                url: 'https://192.168.1.115:9440/PrismGateway/services/rest/v1/vms/',
                data: newVM
            }).then(function successCallback(resource){
                console.log("OK");
            })
        }
    }])
    
    .service('networkService', [function(){
        this.networks = [
            {  

                "name": "nxt1",
                "vlanID": "1",
                "gateway": "192.168.1.1/24",
                "dnsServer": "208.201.1.204",
                "domains": "",
                "pools": [],
                "creatingTime": "2015/10/10 09:11:12"
            },
            {
                "name": "nxt2",
                "vlanID": "2",
                "gateway": "192.167.1.1/24",
                "dnsServer": "208.201.1.204",
                "domains": "",
                "pools": [],
                "creatingTime": "2015/10/11 09:51:12"
            },
            {
                "name": "nxt3",
                "vlanID": "3",
                "gateway": "192.166.1.1/24",
                "dnsServer": "208.201.1.204",
                "domains": "",
                "pools": [],
                "creatingTime": "2015/10/12 13:11:12"
            }
        ];
        this.addNetwork = function(name, vlanID, gateway, dnsServer, domains, pools) {
            this.networks.push({
                name: name,
                vlanID: vlanID,
                gateway: gateway,
                dnsServer: dnsServer,
                domains: domains,
                pools: pools,
                creatingTime: new Date().format('yyyy/MM/dd HH:mm:ss'),
            });
        }
    }])
    
    // =========================================================================
    // Todo List Widget Data
    // =========================================================================

    .service('todoService', ['$resource', function($resource){
        this.getTodo = function(todo) {
            var todoList = $resource("data/todo.json");
            
            return todoList.get({
                todo: todo
            });
        }
    }])


    // =========================================================================
    // Recent Items Widget Data
    // =========================================================================
    
    .service('recentitemService', ['$resource', function($resource){
        this.getRecentitem = function(id, name, price) {
            var recentitemList = $resource("data/recent-items.json");
            
            return recentitemList.get ({
                id: id,
                name: name,
                price: price
            })
        }
    }])


    // =========================================================================
    // Recent Posts Widget Data
    // =========================================================================
    
    .service('recentpostService', ['$resource', function($resource){
        this.getRecentpost = function(img, user, text) {
            var recentpostList = $resource("data/messages-notifications.json");
            
            return recentpostList.get ({
                img: img,
                user: user,
                text: text
            })
        }
    }])
    
    // =========================================================================
    // Data Table
    // =========================================================================
    
    .service('tableService', [function(){
        this.data = [
            {
                "id": 10238,
                "name": "Marc Barnes",
                "email": "marc.barnes54@example.com",
                "username": "MarcBarnes",
                "contact": "(382)-122-5003"
            },
            {   
                "id": 10243,
                "name": "Glen Curtis",
                "email": "glen.curtis11@example.com",
                "username": "GlenCurtis",
                "contact": "(477)-981-4948"
            },
            {
                "id": 10248,
                "name": "Beverly Gonzalez",
                "email": "beverly.gonzalez54@example.com",
                "username": "BeverlyGonzalez",
                "contact": "(832)-255-5161"
            },
            {
                "id": 10253,
                "name": "Yvonne Chavez",
                "email": "yvonne.chavez@example.com",
                "username": "YvonneChavez",
                "contact": "(477)-446-3715"
            },
            {
                "id": 10234,
                "name": "Melinda Mitchelle",
                "email": "melinda@example.com",
                "username": "MelindaMitchelle",
                "contact": "(813)-716-4996"
                
            },
            {
                "id": 10239,
                "name": "Shannon Bradley",
                "email": "shannon.bradley42@example.com",
                "username": "ShannonBradley",
                "contact": "(774)-291-9928"
            },
            {
                "id": 10244,
                "name": "Virgil Kim",
                "email": "virgil.kim81@example.com",
                "username": "VirgilKim",
                "contact": "(219)-181-7898"
            },
            {
                "id": 10249,
                "name": "Letitia Robertson",
                "email": "letitia.rober@example.com",
                "username": "Letitia Robertson",
                "contact": "(647)-209-4589"
            },
            {
                "id": 10237,
                "name": "Claude King",
                "email": "claude.king22@example.com",
                "username": "ClaudeKing",
                "contact": "(657)-988-8701"
            },
            {
                "id": 10242,
                "name": "Roland Craig",
                "email": "roland.craig47@example.com",
                "username": "RolandCraig",
                "contact": "(932)-935-9471"
            },
            {
                "id": 10247,
                "name": "Colleen Parker",
                "email": "colleen.parker38@example.com",
                "username": "ColleenParker",
                "contact": "(857)-459-2792"
            },
            {
                "id": 10252,
                "name": "Leah Jensen",
                "email": "leah.jensen27@example.com",
                "username": "LeahJensen",
                "contact": "(861)-275-4686"
            },
            {
                "id": 10236,
                "name": "Harold Martinez",
                "email": "martinez67@example.com",
                "username": "HaroldMartinez",
                "contact": "(836)-634-9133"
            },
            {
                "id": 10241,
                "name": "Keith Lowe",
                "email": "keith.lowe96@example.com",
                "username": "KeithLowe",
                "contact": "(778)-787-3100"
            },
            {
                "id": 10246,
                "name": "Charles Walker",
                "email": "charles.walker90@example.com",
                "username": "CharlesWalker",
                "contact": "(486)-440-4716"
            },
            {
                "id": 10251,
                "name": "Lillie Curtis",
                "email": "lillie.curtis12@example.com",
                "username": "LillieCurtis",
                "contact": "(342)-510-2258"
            },
            {
                "id": 10235,
                "name": "Genesis Reynolds",
                "email": "genesis@example.com",
                "username": "GenesisReynolds",
                "contact": "(339)-375-1858"
            },
            {
                "id": 10240,
                "name": "Oscar Palmer",
                "email": "oscar.palmer24@example.com",
                "username": "OscarPalmer",
                "contact": "(544)-270-9912"
            },
            {
                "id": 10245,
                "name": "Lena Bishop",
                "email": "Lena Bishop",
                "username": "LenaBishop",
                "contact": "(177)-521-1556"
            },
            {
                "id": 10250,
                "name": "Kent Nguyen",
                "email": "kent.nguyen34@example.com",
                "username": "KentNguyen",
                "contact": "(506)-533-6801"
            }
        ];
    }])


    // =========================================================================
    // Malihu Scroll - Custom Scroll bars
    // =========================================================================
    .service('scrollService', function() {
        var ss = {};
        ss.malihuScroll = function scrollBar(selector, theme, mousewheelaxis) {
            $(selector).mCustomScrollbar({
                theme: theme,
                scrollInertia: 100,
                axis:'yx',
                mouseWheel: {
                    enable: true,
                    axis: mousewheelaxis,
                    preventDefault: true
                }
            });
        }
        
        return ss;
    })


    //==============================================
    // BOOTSTRAP GROWL
    //==============================================

    .service('growlService', function(){
        var gs = {};
        gs.growl = function(message, type) {
            $.growl({
                message: message
            },{
                type: type,
                allow_dismiss: false,
                label: 'Cancel',
                className: 'btn-xs btn-inverse',
                placement: {
                    from: 'top',
                    align: 'right'
                },
                delay: 2500,
                animate: {
                        enter: 'animated fadeIn',
                        exit: 'animated fadeOut'
                },
                offset: {
                    x: 20,
                    y: 85
                }
            });
        }
        
        return gs;
    })
